package lego.jbv;

/*
 *  Arbiter pass the highest priority car command
 *  from the behaviors to the car driver.   
 */
public class Arbiter extends Thread
{
	private ICommand[] commands;
	private CarControl carControl;
	
    public Arbiter(ICommand[] _commands)
    {
    	commands = _commands;
    	carControl = new CarControl();
    }
    	
	public void run()
	{
	    while ( true )
	    {
		    for (int i=0; i < commands.length; i++)
		    {
		    	CarCommand.Command carCommand = commands[i].getCommand();
		    	if ( carCommand != null)
		    	{
		    		carControl.perform(carCommand);	
		    		break;
		    	}
		    }
		   		   
	    }

    }
}
	

